package app.project.directionlensproject.util;

import android.content.Context;
import android.hardware.Camera;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

class CameraSurface extends SurfaceView
  implements SurfaceHolder.Callback
{
  Camera mCamera;
  SurfaceHolder mHolder = getHolder();

  CameraSurface(Context paramContext)
  {
    super(paramContext);
    this.mHolder.addCallback(this);
    this.mHolder.setType(3);
  }

  public void surfaceChanged(SurfaceHolder paramSurfaceHolder, int paramInt1, int paramInt2, int paramInt3)
  {
    if (this.mCamera != null)
    {
      Camera.Parameters localParameters = this.mCamera.getParameters();
      Camera.Size localSize = (Camera.Size)localParameters.getSupportedPreviewSizes().get(0);
      localParameters.setPreviewSize(localSize.width, localSize.height);
      this.mCamera.setParameters(localParameters);
      this.mCamera.startPreview();
      Log.i("Camera-Surface Changed", "h is " + paramInt3 + " w is " + paramInt2 + "; width is " + localSize.width + " height is " + localSize.height);
    }
  }

  public void surfaceCreated(SurfaceHolder paramSurfaceHolder)
  {
    Log.i("CameraSurface", "Surface Created");
    try
    {
      this.mCamera = Camera.open();
      this.mCamera.setPreviewDisplay(paramSurfaceHolder);
      return;
    }
    catch (Exception localException)
    {
      Log.i("CameraSurface", "Exception while opening camera. Message is " + localException.getMessage());
      if (this.mCamera != null)
        this.mCamera.release();
      this.mCamera = null;
    }
  }

  public void surfaceDestroyed(SurfaceHolder paramSurfaceHolder)
  {
    Log.i("CameraSurface", "Surface destroyed");
    if (this.mCamera != null)
    {
      this.mCamera.stopPreview();
      this.mCamera.setPreviewCallback(null);
      this.mCamera.release();
      this.mCamera = null;
    }
  }
}